#include<iostream>
#include<queue>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<list>
using namespace std;
string g_path = "./fcfs.txt";

typedef class Process
{
public:
	string _process_name;
	int _arrive_time; // 到达时间
	int _server_time; // 服务时间

	int _finsh_time;// 完成时间
	

	Process(string& process_name, int arrive_time, int server_time)
		:_process_name(process_name), _arrive_time(arrive_time), _server_time(server_time)
	{}
	Process() {}
}PCB;

auto cmp1 = [](const Process& p1, const Process& p2) { return p1._arrive_time< p2._arrive_time; };
auto cmp2 = [](const Process& p1, const Process& p2) { return p1._server_time > p2._server_time; }; // 小堆
list<Process> l;
priority_queue<Process, vector<Process>, decltype(cmp2)> pq(cmp2);

void Read(string file_path = g_path)
{
	ifstream file(g_path);
	if (!file.is_open())
	{
		cout << "打开文件失败" << endl;
	}

	string header;
	getline(file, header); // 丢弃第一行
	//cout << header.c_str() << endl;
	string line;
	cout << "进程名" << "\t" << "到达时间" << "\t" << "服务时间" << endl;
	while (getline(file, line))
	{
		istringstream iss(line); // 需要 sstream头文件
		Process p;
		iss >> p._process_name >> p._arrive_time >> p._server_time;
		
		cout << p._process_name << "\t" << p._arrive_time << "\t\t" << p._server_time << endl;
		l.push_back(p);
	}
	cout << "============================" << endl;
}

// 先服务到达 且 服务时间最短的进程
void Schedule() 
{
	int current_time = 0;
	int finsh_time = -1;
	bool is_busy = false;
	while (true) 
	{
		if (current_time == finsh_time) 
		{
			is_busy = false;
			cout << "该进程运行结束" << endl;
		}
		for (auto it : l) 
		{
			if(current_time >)
		}
		current_time++;
	}
}

int main()
{

	cout << "开始从文件中读取信息" << endl;
	Read();
	//Cal();




	return 0;
}